package www.bplead.com.mydemo.activity;

import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import www.bplead.com.mydemo.R;
import www.bplead.com.mydemo.fragment.BluetoothPrintFragment;
import www.bplead.com.mydemo.fragment.HotelSendFragment;
import www.bplead.com.mydemo.fragment.RecycleSiteFragment;

public class LayoutViewDrawerActivity extends AppCompatActivity implements View.OnClickListener,NavigationView.OnNavigationItemSelectedListener{
    private static final String TAG = "LayoutViewDrawerActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.drawer_index);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        View view = navigationView.getHeaderView(0);

        TextView userName = (TextView) view.findViewById(R.id.lot_acount);
        TextView quitButton = (TextView) view.findViewById(R.id.lot_quit_account);
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        int id = item.getItemId();
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        switch (id){
            case R.id.menu_hotel_send:
                fragmentTransaction.replace(R.id.drawer_layout_content,new HotelSendFragment());
                break;
            case R.id.menu_bluetooth_print:
                fragmentTransaction.replace(R.id.drawer_layout_content,new BluetoothPrintFragment());
                break;
            case R.id.menu_recycle_site:
                fragmentTransaction.replace(R.id.drawer_layout_content,new RecycleSiteFragment());
                break;
        }
        fragmentTransaction.commit();

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);

        return true;
    }
}
